package com.shuzi.MediaShare.gui.history;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.shuzi.MediaShare.R;
import com.shuzi.MediaShare.base.BaseFrameAtivity;
import com.shuzi.MediaShare.control.CacheDataManager;
import com.shuzi.MediaShare.gui.movie.MovieDetailPlayerActivity;
import com.shuzi.MediaShare.gui.movie.MovieHomeAdapter;
import com.shuzi.MediaShare.model.MovieInfo;
import com.shuzi.MediaShare.view.LoadMoreScrollListener;
import com.shuzi.MediaShare.view.LoadMoreScrollListener.setOnScrollToEndListener;

/**
 * 历史记录页面
 * 
 * @author lung 下午5:17:11 2013
 */
public class HistoryActivity extends BaseFrameAtivity
{

	/** 电影列表 */
	private List<MovieInfo> mediaInfos = null;

	/** 显示列表 */
	private GridView gridView = null;

	/** 适配器 */
	private MovieHomeAdapter adapter = null;

	@SuppressWarnings("unchecked")
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		gridView = (GridView) findViewById(R.id.movie_gridView);
		mediaInfos = (List<MovieInfo>) CacheDataManager.getInstance()
				.getCacheDataToFile(this, "HISTORY");
		adapter = new MovieHomeAdapter(this, mediaInfos);
		gridView.setOnItemClickListener(new OnItemClickListener()
		{

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id)
			{
				if (mediaInfos != null && !mediaInfos.isEmpty())
				{
					Intent intent = new Intent();
					intent.setClass(HistoryActivity.this,
							MovieDetailPlayerActivity.class);
					intent.putExtra("MOVIEINFO", mediaInfos.get(position));
					startActivity(intent);
				}
			}
		});
		gridView.setOnScrollListener(new LoadMoreScrollListener(ImageLoader
				.getInstance(), true, true, new setOnScrollToEndListener()
		{

			@Override
			public void loadMoreWhenScrollToEnd()
			{
				// loadMoreData();

			}

		}));
		titileBarLayout.typeButton.setVisibility(View.GONE);
		titileBarLayout.choiceButton.setVisibility(View.GONE);
		loadData();
	}

	@Override
	protected boolean initData(Integer... params)
	{
		return true;
	}

	@Override
	protected void refreshView(boolean isSuccessful, Integer... params)
	{
		gridView.setAdapter(adapter);
		adapter.notifyDataSetChanged();

	}

	@Override
	protected void tryAgain()
	{

	}

	@Override
	protected View setCenterView()
	{
		return View.inflate(this, R.layout.movie_home, null);
	}

}
